import MJCrequest from "./request/index";
import { BASE_URL, TIME_OUT } from "./request/config";
import { getToken } from "auth-provider";

//请求出口
const MJCrequestingToast = new MJCrequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptor: (config: any) => {
      const token = getToken();
      if (token) {
        if (config) {
          config.headers.authorization = "Bearer " + token;
        }
      }
      return config;
    },
    requestInterceptorCatch: (config) => {
      console.log("请求失败");
      return config;
    },
    responseInterceptor: (res) => {
      return res.data;
    },
    responseInterceptorCatch: (err) => {
      return Promise.reject(err);
    },
  },
  isMessageToast: true,
});
export default MJCrequestingToast;
